package com.kimo3412.amqp_test.service;

// LogConsumer.java
import com.kimo3412.amqp_test.entity.LogEntry;
import com.kimo3412.amqp_test.repository.LogEntryRepository;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LogConsumer {
    @Autowired
    private LogEntryRepository logEntryRepository;

    @RabbitListener(queues = "logQueue")
    public void receiveLog(String message) {
        LogEntry logEntry = new LogEntry();
        logEntry.setMessage(message);
        logEntryRepository.save(logEntry);
        System.out.println("Received log: " + message);
    }
}
